﻿/**
 * 
 * Copyright 2009 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace moose.irc.standard
{

    [CLSCompliant(true)]
    [Response(
        name = "Server Name/Version Response",
        description = "stores server name and version information, and echos server response as status message",
        author = "Mike MacKenzie-Jamer <email: mikejamer@gmail.com>",
        version = "0.1")]
    [Trigger(TriggerText = "002")]
    public sealed class raw002Response : IrcAction
    {
        protected override IrcState valid_states()
        {
            return IrcState.Registered;
        }

        protected override void action(IrcClient client, IrcMessage input)
        {

            string message = MessageUtility.print(input);
            string server_name = string.Empty;
            string server_version = string.Empty;
            int start, end;
            start = message.IndexOf("is ");
            end = message.IndexOf(",");

            client.setServerSetting("server_name", message.Substring(
                start, end - start
                ));

            start = message.IndexOf("version ");
            client.setServerSetting("server_version", message.Substring(start));

            client.echo(message);

            return;
        }
    }
}
